﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Rtgs.master" AutoEventWireup="true"
    CodeFile="sys_t_user_rolelist.aspx.cs" Inherits="RTGS.Web.page.usermanagement.sys_t_user_rolelist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="Server">
    <script type="text/javascript">
     function LoadRole() {
         $lstRoleLeft = $('#lstRoleLeft');
         $.ajax({
             type: 'POST',
             url: '<%= ResolveClientUrl("~/ajaxhandler/usermanagement/sys_t_role.ashx?method=getdataallrole") %>',
             contentType: 'application/json',
             dataType: 'json',
             success: function (datas) {
                 $.each(datas, function (i, data) {

                     $lstRoleLeft.append('<option value="' + data.roleId + '">' + data.roleName + '</option>');

                 });
             },
             error: function () {
                 alert("Failed to load role");
             }
         });

     }

     $(document).ready(function () {
         function ClearText() {
             $('#txtUserCode').val('');
         }
         LoadRole();

         $('#btnMoveLeft').click(function () {
             $("#lstRoleRight > option:selected").each(function () {
                 $(this).remove();
             });
         }
        );


         $('#btnMoveRight').click(function () {

             var selectedOpts = $('#lstRoleLeft option:selected');
             if (selectedOpts.length == 0) {
                 alert("Nothing to move.");
             }


             var result = false;
             $("#lstRoleRight option").each(
                           function (index, option) {

                               if (selectedOpts.val() == option.value) {
                                   result = true;
                               }

                           });

             if (result == false) {
                 $('#lstRoleRight').append($(selectedOpts).clone());
             }
         });



         $('#btnMoveLeftAll').click(function () {

             var selectedOpts = $('#lstRoleRight option');
             selectedOpts.remove();
         }
        );

         $('#btnMoveRightAll').click(function () {

             var selectedOptsRight = $('#lstRoleRight option');
             selectedOptsRight.remove();

             var selectedOpts = $('#lstRoleLeft option');

             $('#lstRoleRight').append($(selectedOpts).clone());
         }
        );


         $('#btnSave').click(function () {

             var UserId = $("#txtUserID").val()
             if (UserId != "") {
                 var role_id = [];
                 var user_id = [];
                 var param = "";
                 user_id.push($("#txtUserID").val());
                 $("#lstRoleRight option").each(
                           function (index, option) {
                               role_id.push(option.value);

                           });

                 CallAjax('<%= ResolveClientUrl("~/ajaxhandler/usermanagement/sys_t_user_role.ashx") %>', '?method=insert&roleId=' + role_id + '&userId=' + user_id);
             }
             else {
                 alert("Pilih User terlebih dahulu");
             }
         });



         $('#btnBrowse').click(function () {

             $('#dialog').load('<%= ResolveClientUrl("~/form/usermanagement/sys_t_user_roleform.aspx") %>').dialog({ modal: true, width: 630, title: 'Find User' });
         }
        );

     });        
        
    </script>
    <div>
        <table cellpadding="2" cellspacing="2" border="0">
            <tr>
                <td>
                    User :
                    <input type="text" disabled="disabled" style="width: 215px;" name="txtUserCode" id="txtUser"
                        value="" />
                </td>
                <td colspan="2">
                    <input id="btnBrowse" type="button" value="..." style="width: 50px;" />
                </td>
            </tr>
            <tr>
                <th align="left">
                    Available Role
                </th>
                <th>
                </th>
                <th align="left">
                    Selected Role
                </th>
            </tr>
            <tr>
                <td>
                    <select id="lstRoleLeft" multiple="multiple" size="10" style="width: 250px; height: 300px;">
                    </select>
                </td>
                <td>
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td>
                                <input id="btnMoveRight" type="button" value=">" style="width: 50px;" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="btnMoveLeft" type="button" value="<" style="width: 50px;" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="btnMoveRightAll" type="button" value=">>" style="width: 50px;" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="btnMoveLeftAll" type="button" value="<<" style="width: 50px;" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <select id="lstRoleRight" multiple="multiple" size="10" style="width: 250px; height: 300px;">
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <input id="btnSave" type="button" value="Save" style="width: 50px;" />
                </td>
            </tr>
        </table>
    </div>
    <div id="dialog" title="Default dialog">
    </div>
    <input type="hidden" name="txtUserID" id="txtUserID" value="" />
</asp:Content>
